/**
 * @name wushain
 * @carousel
 * @time 2015/11/13
 * &time    时间
 * &num     索引个数
 * &bgImgs  NEXT背景动画数组
 * &bgImgF  Previous背景动画数组
 * &animate 轮播动画
 */
var Slide = {
    createNew:function(time,num,bgImgs,bgImgF,animate){
//private
        var length=num;//索引个数
        var Slide={};
        var nextReference;//下级索引
        var reference;//当前索引
//initialization
        Slide.initialization=function(){
            $(".carousel-img img:first").siblings('img').css('display','none');
            $(".carousel-img img").each(function(){
                $(this).data('index',$(this).index());
            });
            this.SlideClickR();
            this.SlideClickL();
        };
//right
        Slide.SlideClickR= function(){
            $('.my-arrow-right a').click(function(){
                $(".carousel-img img").each(function () {
                    if(!$(this).is(":hidden")){
                        $(this).css('display','none');
                        reference=$(this).index();//索引
                        nextReference= judgeNext(reference);//获得下级索引
                    }
                });
                $(".carousel-img img").eq(nextReference).css('display','block').addClass('animated '+animate);
                bgNextControl(reference,nextReference);
            });
        };
//left
        Slide.SlideClickL= function () {
            $('.my-arrow-left a').click(function(){
                $(".carousel-img img").each(function () {
                    if(!$(this).is(":hidden")){
                        $(this).css('display','none');
                        reference=$(this).index();//索引
                        nextReference= judgePrevious(reference);//获得下级索引
                    }
                });
                $(".carousel-img img").eq(nextReference).css('display','block').addClass('animated '+animate);
                bgPreviousControl(reference,nextReference);
            });
        };

        setInterval(function () {
            $('.my-arrow-right a').click();
        },time);

        function judgeNext(reference){
            if(reference<(length-1)){
                return reference+1;
            }
            if(reference==(length-1)){
                return 0;
            }
        }
        function judgePrevious(reference){
            if(reference>0){
                return reference-1;
            }
            if(reference==0){
                return (length-1);
            }
        }
//bgController
        function bgNextControl(reference,nextReference){
            for(var i=0;i<length;i++){
                $('.carousel').removeClass(bgImgF[i]);
            }
            if(reference==0){
                $('.carousel').removeClass(bgImgs[length-1]).addClass('animated2 '+bgImgs[0]);
            }
            if(reference>0){
                $('.carousel').removeClass(bgImgs[reference-1]).addClass('animated2 '+bgImgs[reference]);
            }
        }

        function bgPreviousControl(reference,nextReference){
            for(var i=0;i<length;i++){
                $('.carousel').removeClass(bgImgs[i]);
            }
            if(reference==(length-1)){
                $('.carousel').removeClass(bgImgF[0]).addClass('animated2 '+bgImgF[reference]);
            }
            if(reference<(length-1)){
                $('.carousel').removeClass(bgImgF[reference+1]).addClass('animated2 '+bgImgF[reference]);
            }
        }
//final
        return Slide;
    }
};


